package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AuditNode;
import com.ruoyi.system.service.IAuditNodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审批流配置Controller
 * 
 * @author ruoyi
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/system/auditNode")
public class AuditNodeController extends BaseController
{
    @Autowired
    private IAuditNodeService auditNodeService;

    /**
     * 查询审批流配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuditNode auditNode)
    {
        startPage();
        List<AuditNode> list = auditNodeService.selectAuditNodeList(auditNode);
        return getDataTable(list);
    }

    /**
     * 查询审批流配置不分页
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:list')")
    @GetMapping("/noPageList")
    public AjaxResult noPageList(@RequestParam String auditBusinessType)
    {
        List<AuditNode> list = auditNodeService.noPageList(auditBusinessType);
        return success(list);
    }

    /**
     * 导出审批流配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:export')")
    @Log(title = "审批流配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuditNode auditNode)
    {
        List<AuditNode> list = auditNodeService.selectAuditNodeList(auditNode);
        ExcelUtil<AuditNode> util = new ExcelUtil<AuditNode>(AuditNode.class);
        util.exportExcel(response, list, "审批流配置数据");
    }

    /**
     * 获取审批流配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:query')")
    @GetMapping(value = "/{auditNodeId}")
    public AjaxResult getInfo(@PathVariable("auditNodeId") Long auditNodeId)
    {
        return success(auditNodeService.selectAuditNodeByAuditNodeId(auditNodeId));
    }

    /**
     * 新增审批流配置
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:add')")
    @Log(title = "审批流配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuditNode auditNode)
    {
        return toAjax(auditNodeService.insertAuditNode(auditNode));
    }


    /**
     * 保存审批流配置
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:save')")
    @Log(title = "审批流配置", businessType = BusinessType.SAVE)
    @PostMapping("save")
    public AjaxResult save(@RequestBody List<AuditNode> auditNodes)
    {
        return toAjax(auditNodeService.saveAuditNode(auditNodes));
    }

    /**
     * 修改审批流配置
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:edit')")
    @Log(title = "审批流配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuditNode auditNode)
    {
        return toAjax(auditNodeService.updateAuditNode(auditNode));
    }

    /**
     * 删除审批流配置
     */
    @PreAuthorize("@ss.hasPermi('system:auditNode:remove')")
    @Log(title = "审批流配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{auditNodeIds}")
    public AjaxResult remove(@PathVariable Long[] auditNodeIds)
    {
        return toAjax(auditNodeService.deleteAuditNodeByAuditNodeIds(auditNodeIds));
    }
}